import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Test3 {
    static final String JDBC_DRIVER ="com.mysql.cj.jdbc.Driver";
    static final String DB_RUL = "jdbc:mysql://localhost:3306/jdbcdemo";
    static final String USER ="root";
    static final String PASS = "";
    public static void main(String[] args) {
        try {
            Class.forName(JDBC_DRIVER);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        try(Connection coon = DriverManager.getConnection(DB_RUL,USER,PASS);
            Statement stat = coon.createStatement()
        ){
            //创建表
//            String string = "CREATE TABLE user" +
//                    "(id INTEGER PRIMARY KEY AUTO_INCREMENT," +
//                    "username VARCHAR(20)," +
//                    "userpass VARCHAR(10) NOT NULL," +
//                    "age INTEGER);";
//            int i = stat.executeUpdate(string);
            //添加数据
//            String string = "INSERT INTO user(username,userpass,age) VALUE" +
//                    "('admin','123',18),('kaifamiao','1234',20),('kaifamiao2','1234',22)";
//            int i = stat.executeUpdate(string);
            //修改数据
//            String string = "UPDATE user SET userpass='456' WHERE username='admin'";
//            int i = stat.executeUpdate(string);
            //删除数据
            String string = "DELETE FROM user WHERE id = 2";
            int i = stat.executeUpdate(string);
            if (i >= 1){
                System.out.println("创建成功");
            }else {
                System.out.println("创建失败");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
